<?php

namespace App\Models;

use App\Models\Traits\VendorTrait;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;

/**
 * App\Models\Vendor
 *
 * @property int $id
 * @property string $name
 * @property string|null $phone
 * @property string|null $initial_code initial password
 * @property int $is_disabled
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Product[] $products
 * @property-read int|null $products_count
 * @method static \Database\Factories\VendorFactory factory(...$parameters)
 * @method static \Illuminate\Database\Eloquent\Builder|Vendor newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|Vendor newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|Vendor query()
 * @method static \Illuminate\Database\Eloquent\Builder|Vendor whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Vendor whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Vendor whereInitialCode($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Vendor whereIsDisabled($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Vendor whereName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Vendor wherePhone($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Vendor whereUpdatedAt($value)
 * @mixin \Eloquent
 */
class Vendor extends Model
{
    use HasFactory, VendorTrait;
    
    protected $guarded = ['id'];
	
	public static function trees()
	{
		$vendors = [0 => '请选择'];
		foreach (self::where('is_disabled', false)->get() as $vendor) {
			$vendors[$vendor->id] = $vendor->name;
		}
		return collect($vendors);
	}
	
	public function products()
	{
		return $this->hasMany(Product::class);
	}
}
